/***************************************************************************
 创建者: 华磊
 开始时间: 2020.8.14
 copyright: (C) 深圳市华友高科有限公司
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2020.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file x.h
 *  功能:
 *
 *                                                                         *
 ***************************************************************************/
#ifndef MAPDELEGATE_H
#define MAPDELEGATE_H
#include <qstring.h>
#include <vector>
#ifdef BUILD_X86_LINUX
#include "../CommunicateDelegate/gSoapFoundation/soapStub.h"
#endif
#include "../CommunicateDelegate/globaldata.h"


//class MapView;
class CommunicateNormalDelegate;
class CommunicateUpdateDelegate;
//using namespace hmigsoapnamespace;
/**
 * @brief The MapDelegate class 地图视图逻辑处理类
 */
class MapDelegate
{
public:
    /**
     * @brief MapDelegate
     * @param communicateNormalIn 通讯类
     */
    MapDelegate(CommunicateNormalDelegate *communicateNormalIn,GlobalData *globalDataIn,
                CommunicateUpdateDelegate *communicateUpdateIn);

public:

    int getAmclDebugInfo(struct AmclDebugInfo &debugInfoOut);


    int getMapPropertyInfo(std::string mapName,struct MapPropertyInfo &infoOut);
    GlobalData *getGlobalData();
    CommunicateNormalDelegate *getDelegate();
    int getFleetMap(std::string mapName,std::string &mapInfoReturn);
    int writeFleetMap( std::string mapName, std::string &mapInfoIn);

    void cleanAllMessage();
    int setAllManualServon(int nServOffOn,int &returnFlag);
    bool isUseFtpStatus();
    int setUpdatePointCloud(bool isEnable);
    bool get_isDisplayAllReferenceMarks();
    bool get_isDisplayCalculatedReferenceMarks();
    bool get_isDisplayDetectedLaserPoints();
    int setDisplayAllReferenceMarks(bool isDisplay);
    int setDisplayCalculatedReferenceMarks(bool isDisplay);
    int setDisplayDetectedLaserPoints(bool isDisplay);
    int getAllReferenceMarks(std::vector<struct ReflectMarkInfo> &reflectMarksOut);
    int addReferenceMarkToMap(struct ReflectMarkInfo markIn,int &returnFlag);
    int saveReferenceMarkToFile(std::string fileNameIn,int &returnFlag);
    int deleteReferenceMarkInMap(int uniqId,int &returnFlag);
    int getReflectDebugInfo(struct ReflectDebugInfo &matchDebugInfoOut);
    int setOriginalLaserFilterType(int typeIn,int &returnFlag);
    int getMotionEngineStatus();
    int getHandControlType();
    int getServoStatus();
    int setDefaultMapName(std::string fileNameIn, int &returnFlag);
    int setCheckVehiclePosition_amcl(bool isCheck,int &returnFlag);
    int setLaserIntensityFilterByType_visionMatch(int typeIn,int &returnFlag);
    int setUltrasonicSensorCheckEnable(bool isOn,int &returnFlag);
    int setPointCloudCheckEnable(bool isOn,int &returnFlag);
    int moveToNavgationPoint(struct MovingToNavagationParameter parameterIn,int &returnFlag);
    int getVehiclePositionInQRcode(struct PositionInfo_hmi &positionReturn);
    int getVehiclePositionInCU1(struct PositionInfo_hmi &positionReturn);
    int getVehiclePositionInVmark(struct PositionInfo_hmi &positionReturn);
    int getVehiclePositionInWorld(struct PositionInfo_hmi& positionReturn);
    int setCurrentVMarkIndex(int indexIn, int &returnFlag);
    int setCurrentVMarkType(int currentVmarkTypeIn,int &returnFlag);
    int getVmarkInfoList(std::vector<struct VMarkInfo> &vmarkInfoOut);
    int updateVMarkFile(std::string vmarkFileIn,int &returnFlag);
    int createVMark(struct VMarkInfo infoIn, std::string vmarkFileIn, int &returnFlag);
    int getVMarkPositionInWorld( struct PositionInfo_hmi &positionReturn);
    int getMatchDebugInfo_vmark(struct VisionMatchDebugInfo &infoOut);
    int getQrcodeDebugInfo(QrcodeDebugInfo &infoOut);
//    int setLaserFilterByType_vmark(int typeIn,int &returnFlag);
    /**
     * @brief getDefaultMapName 获取默认地图
     * @return
     */
    QString getDefaultMapName();

    /**
     * @brief vehicleJog 手动
     * @param xMove　ｘ方向平移　（－１，１）
     * @param yMove　ｙ方向平移　（－１，１）
     * @param rotate R方向旋转　（－１，１）
     * @param returnFlag
     * @return
     */
    int vehicleJog(double xMove, double yMove, double rotate, int &returnFlag);

    //地图
    int setMapSolver(enum E_MAP_SOLVER solverIn,
                     int laserCount,int &returnFlag);
    /**
     * @brief createMapStart 开始创建地图
     * @param returnFlag
     * @return
     */
    int createMapStart(int &returnFlag);
    /**
     * @brief createMapEnd　结束创建地图并保存
     * @param mapName　保存地图文件名字
     * @param returnFlag
     * @return
     */
    int createMapEnd(std::string mapName,int &returnFlag);
    /**
     * @brief loadMap
     * @param mapName
     * @param returnFlag
     * @return
     */
    int loadMap(std::string mapName,int &returnFlag);
    int deleteMap(std::string mapName,int &returnFlag);

    //添加虚拟墙
    int addVitrualBlock(std::string configFilePath,int &returnFlag);
    int deleteVitrualBlock(int &returnFlag);
    int addForbidenZone(double x_start,double y_start
                        ,double x_end,double y_end,int &returnFlag);

    //定位
    int setOdomSolver(enum E_ODOM_SOLVER solverIn,int &returnFlag);
    int setLocationSolver(E_LOCATION_SOLVER solverIn, int &returnFlag);
//    int getVehiclePosition(struct VehiclePosition& positionReturn);
    int setVehiclePosition(struct VehiclePosition positionIn,int &returnFlag);

    //轨迹规划和行驶
    int setReplanCoutLimitWhenFailure(int countLimit,int &returnFlag);
    int setTrajectoryGlobalPlanSolver(enum E_TRAJECTORY_GLOBAL_SOLVER solverIn,int &returnFlag);
    int setTrajectoryLocalPlanSolver(enum E_TRAJECTORY_LOCAL_SOLVER solverIn,int &returnFlag);
    int moveToPosition(struct VehiclePosition positionIn,
                       double velocity,int &returnFlag);
    int moveFollowPath(std::vector<struct VehiclePosition> pathIn,
                       double velocity,int &returnFlag);
    int changeVelocity(double velocity,int &returnFlag);
    int getMovingStatus(enum E_GOAL_STATUS& status);
    int getRemainningTime(double &timeOut);//notused
    int getRemainningDistance(double &distanceOut);//not used
    int ceaseMotion(int &returnFlag);
    int startMotion(int &returnFlag);
    int cancelMotion(int &returnFlag);

    //设置
    int setPositionArrivedAccuracy(double accuracyIn,int &returnFlag);
    int setLocalPlanRange(double rangeIn,int &returnFlag);
    int setVehicleBorderOffset(std::vector<double> point_x, std::vector<double> point_y,int &returnFlag);
    int setGlobalBarrierOffset(double offsetIn,int &returnFlag);
    int setLocalBarrierOffset(double offsetIn,int &returnFlag);
    int resetRosAll(int &returnFlag);

    //状态
    int getRosPackageStatus(enum E_ROS_PACKAGE package,enum E_ROS_PACKAGE_STATUS &status);

    //IMU校准
    int startImuCalibrate(int &returnFlag);
    int stopImuCalibrate(int &returnFlag);

    /**
     * @brief getCurrentMapName　获取当前地图名字
     * @param mapNameReturn
     * @return
     */
    int getCurrentMapName(std::string &mapNameReturn);
    /**
     * @brief manual_stop　手动停止
     * @param returnFlag
     * @return
     */
    int manual_stop(int &returnFlag);
    /**
     * @brief clear_odomter 归零用户里程计
     * @param returnFlag
     * @return
     */
    int clear_odomter(int &returnFlag);
    /**
     * @brief calibrateVehicle　校准车体
     * @param xOffset　ｘ方向偏差
     * @param yOffset　ｙ方向偏差
     * @param rOffset r方向偏差
     * @param returnFlag
     * @return
     */
    int calibrateVehicle(double xOffset, double yOffset, double rOffset, int &returnFlag);
    /**
     * @brief setVehicleBorderOffset_rect　设置车体轮廓偏差
     * @param front_offsetIn　前方偏差
     * @param back_offsetIn　后方偏差
     * @param left_offsetIn　左侧偏差
     * @param right_offsetIn　右侧偏差
     * @param returnFlag
     * @return
     */
    int setVehicleBorderOffset_rect(double front_offsetIn,double back_offsetIn,
                               double left_offsetIn,double right_offsetIn,int &returnFlag);
    /**
     * @brief get_vehicle_basic_info　获取车体基本信息
     * @param basicInfoReturn
     * @return
     */
    int get_vehicle_basic_info(struct VehicleBasicInfo &basicInfoReturn);
    /**
     * @brief get_map_list　获取地图文件列表
     * @param mapNameListReturn
     * @return
     */
    int get_map_list(std::vector<std::string> &mapNameListReturn);
    /**
     * @brief getAllPointCloud_translated 获取激光点云
     * @param pointCloudOut
     * @return
     */

    int getAllPointCloud_translated(std::vector<struct PointCloudData_3D> &pointCloudOut);


    int getCarBorder(std::vector<struct VehiclePosition> &carBorderOut);

    int getCarBorderOffset(std::vector<struct VehiclePosition> &carBorderOffsetOut);//获取有效边框

    bool isControllerConnected();

private:
//    MapView *mapView;
    CommunicateNormalDelegate *communicateNormal;
    CommunicateUpdateDelegate *communicateUpdate;
    GlobalData *globalData;
    bool isDisplayAllReferenceMarks;
    bool isDisplayDetectedLaserPoints;
    bool isDisplayCalculatedReferenceMarks;
};

#endif // MAPDELEGATE_H
